<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <script>
            /* 
            确定dp数组和下标含义： dp[i][j]表示从(0,0)到(i,j)有dp[i][j]条不同路径
            状态转移方程：dp[i][j]=dp[i-1][j]+dp[i][j-1]
            初始化dp数组 dp[0][0]=1  dp[0][j]=1 dp[i][0]=1
            
            
            */
            var uniquePaths = function (m, n) {
                let dp = new Array(m).fill().map(() => new Array(n).fill(0))
                for (let i = 0; i < m; i++) {
                    dp[i][0] = 1
                }
                for (let j = 0; j < n; j++) {
                    dp[0][j] = 1
                }
                for (let i = 1; i < m; i++) {
                    for (let j = 1; j < n; j++) {
                        dp[i][j] = dp[i - 1][j] + dp[i][j - 1]
                    }
                }
                return dp[m - 1][n - 1]
            }
            uniquePaths(3, 7)
        </script>
    </body>
</html>
